import request from "@/utils/request";
import type {
  onClassificationArray,
  getAttributesListArry,
  tableDataoArr,
  addtableDataoArr,
} from "@/Api/product/model/attr";

enum Api {
  OneClassificationAttr = "/admin/product/getCategory1",
  TowClassificationAttr = "/admin/product/getCategory2",
  ThreeClassificationAttr = "/admin/product/getCategory3",
  getAttributesAttrlist = "/admin/product/attrInfoList",
  addAttributesattr = "/admin/product/saveAttrInfo",
  deleteAttributes = "/admin/product/deleteAttr",
}

/**
 *
 * @returns onClassificationArray  是一个数据 [{},{}]
 */

// 组件渲染就发送一级分类请求
export const getOneClassificationAttr = () => {
  return request.get<any, onClassificationArray>(Api.OneClassificationAttr);
};

/**
 *
 * @param id 请求二级分类数据  id是一级分类 返回对应一级分类的二级分类数据
 * @returns
 */
export const getTowClassificationAttr = (id: number) => {
  return request.get<any, onClassificationArray>(
    Api.TowClassificationAttr + `/${id}`
  );
};

/**
 *
 * @param id 请求三级分类数据  id是二级分类 返回对应二级分类的三级分类数据
 * @returns
 */
export const getThreeClassificationAttr = (id: number) => {
  return request.get<any, onClassificationArray>(
    Api.ThreeClassificationAttr + `/${id}`
  );
};

/**
 *
 * @param category1Id 一级分类id
 * @param category2Id 二级分类id
 * @param category3Id 三级分类id
 * @returns
 */

export const getAttributesAttr = (
  category1Id: number,
  category2Id: number,
  category3Id: number
) => {
  return request.get<any, getAttributesListArry>(
    Api.getAttributesAttrlist + `/${category1Id}/${category2Id}/${category3Id}`
  );
};

/**
 *
 * @param attr 添加请求参数  是一个对象
 * @returns null
 */

// 添加属性接口
export const addAttributesAttr = (attr: addtableDataoArr) => {
  return request.post<any, tableDataoArr>(Api.addAttributesattr, attr);
};
/**
 *
 * @param attr 修改请求参数  是一个对象
 * @returns null
 */

// 修改属性接口
export const reviseAttributesAttr = (attr: addtableDataoArr) => {
  console.log(attr);
  return request.post<any, tableDataoArr>(Api.addAttributesattr, attr);
};

/**
 *
 * @param attrId 删除数据的id
 * @returns null
 */

// 删除属性接口
export const deleteAttributesAttr = (attrId: number) => {
  console.log(attrId);
  return request.delete<any, null>(Api.deleteAttributes + `/${attrId}`);
};

// reviseAttributesAttr
// {
//   attrName: '465',
//     attrValueList: [
//       {
//         "attrId": 0,
//         "valueName": "123"
//       }
//     ],
//       categoryId: 1,
//         categoryLevel: 3,
// }

// 1099
// {
//   "attrName": "string",
//     "attrValueList": [
//       {
//         "attrId": 0,
//         "id": 0,
//         "valueName": "string"
//       }
//     ],
//       "categoryId": 0,
//         "categoryLevel": 0,
//           "id": 0
// }
